package com.tsing.wms.util;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.tsing.wms.config.RedisManager;
import com.tsing.wms.dto.UserDTO;
import com.tsing.wms.exception.CommonException;
import com.tsing.wms.exception.ServerException;

/**
 * @author TheTsing
 */
public class GetLoginUserUtil {

    public static UserDTO getLoginUserInfo(String token, RedisManager redisManager) {
        if (StrUtil.isBlank(token)) {
            throw new ServerException(CommonException.Proxy.TOKEN_IS_REQUIRED);
        }
        UserDTO userDTO = JSONObject.parseObject(redisManager.getString(token), UserDTO.class);
        if (ObjectUtil.isNull(userDTO)) {
            throw new ServerException(CommonException.Proxy.TOKEN_VERIFY_ERROR);
        }
        return userDTO;
    }

}
